package com.hut.oa.model.bean;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * 菜单
 * @author 朱嘉茵
 *
 */
@Entity
@Table(name="menu_")
public class Menu {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="m_id")
	private Long id;//菜单id
	
	@Column(name="m_name",nullable=false)
	private String text;//菜单名称
	
	@Column(name="m_seq")
	private Integer seq=0;//排序
	
	@Column(name="m_path",nullable=false)
	private String href="#";//路径
	
	@Column(name="m_icon",nullable=false)
	private String icon="icon-circle1";//图标
	
	@Column(name="m_is_delete")
	private boolean open=true;//是否开启
	
	//非表字段用@Transient
	@OneToMany
	@Transient
	private List<Menu> children;
	
	@JoinColumn(name="m_father_id")
	@ManyToOne()
	@JsonIgnore
	private Menu parent;//父菜单
	
	@Column(name="m_type")
	private String type;//资源类型
	
	@Column(name="m_power")
	private Integer power;//权限值
	
	/*@OneToMany(mappedBy="menu",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private List<Operate> operates;//该菜单下所有的操作
*/
	public Menu() {
		super();
	}

	public Menu(String text, String href, String icon, Menu parent, String type, Integer power) {
		super();
		this.text = text;
		this.href = href;
		this.icon = icon;
		this.parent = parent;
		this.type = type;
		this.power = power;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	public List<Menu> getChildren() {
		return children; 
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

	public Menu getParent() {
		return parent;
	}

	public void setParent(Menu parent) {
		this.parent = parent;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Integer getPower() {
		return power;
	}

	public void setPower(Integer power) {
		this.power = power;
	}

	@Override
	public String toString() {
		return "Menu [id=" + id + ", text=" + text + ", seq=" + seq + ", href=" + href + ", icon=" + icon + ", open="
				+ open + ", type=" + type + ", power=" + power + "]";
	}

}
